package com.test.resumeanalysis.ui.talent.talent_info

import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.test.resumeanalysis.R
import com.test.resumeanalysis.common.BaseVBFragment
import com.test.resumeanalysis.databinding.FragmentTalentInfoBinding
import com.test.resumeanalysis.viewModel.PublicViewModel


class TalentInfoFragment : BaseVBFragment<FragmentTalentInfoBinding>(FragmentTalentInfoBinding::inflate){

    private val model:PublicViewModel by activityViewModels()
    private val talentInfoViewModel:TalentInfoViewModel by viewModels()

    override fun initView() {
        super.initView()
        setupToolbar(binding.talentInfoToolbar,true)

        binding.talentInfoToolbar.setNavigationOnClickListener {
            findNavController().popBackStack()
        }
        binding.talentInfoToolbar.title = "个人资料" ;

        model.selectedResumeLiveData.observe(this, Observer {
            talentInfoViewModel.getResumeByPosition(it+1)
        })

        talentInfoViewModel.ResumeLiveData.observe(this, Observer {

            val resultData = it.parsing_result
            binding.tvName.text = resultData.basic_info.name

            binding.tvMajor.text = resultData.basic_info.major
            binding.tvDesirePosition.text = resultData.basic_info.desired_position
            binding.tvSelf.text  = resultData.others.self_evaluation
            binding.tvEmail.text  = resultData.contact_info.email
            binding.tvPhone.text  = resultData.contact_info.phone_number
            binding.tvPlace.text  = resultData.basic_info.birthplace_norm
            if (resultData.basic_info.gender=="男"){
                binding.imgHead.setImageResource(R.drawable.boy)
            }else{
                binding.imgHead.setImageResource(R.drawable.girl)
            }
            val linearLayoutManager = LinearLayoutManager(activity)
            val workEpAdapter = WorkEpAdapter()
            binding.rvTalentWork.layoutManager = linearLayoutManager
            binding.rvTalentWork.adapter = workEpAdapter
            if (resultData.work_experience.isNotEmpty()) {
                workEpAdapter.data = resultData.work_experience.toMutableList()
            }
            val eduAdapter = EduAdapter()
            binding.rvTalentStudy.layoutManager =LinearLayoutManager(activity)
            binding.rvTalentStudy.adapter = eduAdapter
            if (resultData.education_experience.isNotEmpty()){
                eduAdapter.data = resultData.education_experience.toMutableList()
            }

        })
    }
}